package com.hanoi.wiki.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.hanoi.wiki.model.json.CategoryTypeJson;

@Entity
@Table(name="CATEGORY_TYPE")
public class CategoryType implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public CategoryType() {
		
	}
	
	public CategoryType(CategoryTypeJson json) {
		this.typeName = json.getTypeName();
		this.status	  = json.getStatus();
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID")
	private Integer id;
	
	@Column(name="TYPE_NAME", length = 200, unique = true, nullable = false)
	private String typeName;
	
	@Column(name="STATUS")
	private Integer status;
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "CAT_CATTYPE", joinColumns = { @JoinColumn(name = "CAT_TYPE_ID")}, inverseJoinColumns = {@JoinColumn(name = "CAT_ID")})
	private List<Category> categories;
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "CATTYPE_CATSUBTYPE", joinColumns = { @JoinColumn(name = "CAT_TYPE_ID")}, inverseJoinColumns = {@JoinColumn(name = "CAT_SUBTYPE_ID")})
	private List<CategorySubType> categorySubTypes;	
	
	
	
	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	public List<CategorySubType> getCategorySubTypes() {
		return categorySubTypes;
	}
	public void setCategorySubTypes(List<CategorySubType> categorySubTypes) {
		this.categorySubTypes = categorySubTypes;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getTypeName() {
		return typeName;
	}
	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}	
}
